package net.m510.autosurfer.nifty;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.List;

import net.m510.autosurfer.NiftyGetMain;
import net.m510.autosurfer.common.DocumentCapturer;
import net.m510.autosurfer.core.process.AbstractSurfProcess;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jsoup.nodes.Document;

public class NiftyBillSave extends AbstractSurfProcess<List<File>> {
	private File outDir;
	private URI baseUri;
	private String fileName=NiftyGetMain.MEISAI_FILENAME;
	private String charset;

	public NiftyBillSave() {
		this(null,null,null,null,null);
	}
	public NiftyBillSave(CloseableHttpClient client,HttpClientContext context,File outDir, String fileName, String charset) {
		super(client,context);
		this.outDir = outDir;
		this.baseUri = URI.create(context.getTargetHost().toURI()).resolve(context.getRequest().getRequestLine().getUri());
		this.fileName = fileName;
		this.charset = charset;
	}
	
	@Override
	public List<File> process(Document doc) throws ClientProtocolException, IOException {
		DocumentCapturer capturer = new DocumentCapturer(client, context, outDir, fileName, charset, baseUri);
//		capturer.setSingle(true);
		return capturer.capture(doc);
	}

	public File getOutDir() {
		return outDir;
	}

	public void setOutDir(File outDir) {
		this.outDir = outDir;
	}

}
